public class text67 {
    /*class Lian
    {
        int val;
        Link.Lian next;

        public Lian(int val) {
            this.val = val;
        }
    }
    public Link.Lian head1;
    public Link.Lian head2;
    public Link.Lian build1()
    {
        Link.Lian a=new Link.Lian(1);
        Link.Lian b=new Link.Lian(2);
        Link.Lian c=new Link.Lian(3);
        Link.Lian d=new Link.Lian(6);
        Link.Lian e=new Link.Lian(7);

        head1=a;
        a.next=b;
        b.next=c;
        c.next=d;
        d.next=e;
        return head1;

    }
    public Link.Lian build2()
    {
        Link.Lian a=new Link.Lian(4);
        Link.Lian b=new Link.Lian(5);
        Link.Lian c=new Link.Lian(6);
        Link.Lian d=new Link.Lian(7);
        head2=a;
        a.next=b;
        b.next=c;
        c.next=d;
        return head2;


    }
    public Link.Lian FindFirstCommonNode(Link.Lian pHead1, Link.Lian pHead2) {
        if(pHead1==null||pHead2==null)
        {
            return null;
        }
        Link.Lian cur1=pHead1;
        Link.Lian cur2=pHead2;
        int count1=0;
        int count2=0;
        while(cur1!=null)
        {
            count1++;
            cur1=cur1.next;
        }
        while(cur2!=null)
        {
            count2++;
            cur2=cur2.next;
        }
        cur1=pHead1;
        cur2=pHead2;

        if(count1>count2)
        {
            int a=count1-count2;
            while(a!=0)
            {
                cur1=cur1.next;
                a--;
            }
        }
        else
        {
            int c=count2-count1;
            while(c!=0)
            {
                cur2=cur2.next;
                c--;
            }
        }
        while(cur1!=null)
        {
            if(cur1==cur2)
            {
                return cur1;
            }
        }
        return null;


    /*class TreeNode
    {
        char val;
        TreeNode left;
        TreeNode right;
        public TreeNode(char val)
        {
            this.val=val;
        }
    }


    // 注意类名必须为 Main, 不要有任何 package xxx 信息
    public class Main {

        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            // 注意 hasNext 和 hasNextLine 的区别
            while (in.hasNextLine()) {
                String s=in.nextLine();
                TreeNode root=build(s);
                dayin(root);



            }

        }
        public static void dayin(TreeNode root)
        {
            if(root==null)
            {
                return;
            }
            dayin(root.left);
            System.out.print(root.val+" ");
            dayin(root.right);
        }
        public static int i=0;
        public static TreeNode build(String s)
        {
            TreeNode root=null;
            if(s.charAt(i)!='#')
            {
                root=new TreeNode(s.charAt(i));
                i++;
                root.left=build(s);
                root.right=build(s);
            }
            else
            {
                i++;
            }
            return root;
            class Solution {
                public List<Integer> preorderTraversal(TreeNode root) {
                    List<Integer>a=new ArrayList<>();
                    if(root==null)
                    {
                        return a;
                    }

                    Stack<TreeNode>b=new Stack<>();


                    TreeNode cur=root;
                    TreeNode top=null;
                    //b.push(cur);
                    //a.add(cur.val);
                    //cur=cur.left;
                    while(!b.empty()||cur!=null)
                    {
                        while(cur!=null)
                        {
                            a.add(cur.val);
                            b.push(cur);
                            cur=cur.left;


                        }


                        top=b.pop();
                        cur=top.right;







                    }
                    return a;

                }







            }
    }

     */


}

